package com.fxwater.redis.service.impl;


import com.fxwater.redis.domain.ItemInfo;
import com.fxwater.redis.mapper.ItemServiceMapper;
import com.fxwater.redis.service.IitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.redis.core.*;

import java.util.List;

@Service
public class ItemServiceImpl implements IitemService {


    @Autowired
    private ItemServiceMapper itemServiceMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public List<ItemInfo> selectItemInfoInfoDataList() {
               // TODO 存入redis数据
              //清空
             while (redisTemplate.opsForList().size("item") > 0){
             redisTemplate.opsForList().leftPop("item");
             }
           //向redis的某个key下面的list列表里面插入一个list列表，不会去重。
            redisTemplate.opsForList().rightPushAll("item", itemServiceMapper.selectItemInfoInfoDataList());

          return itemServiceMapper.selectItemInfoInfoDataList();

    }

    @Override
    public ItemInfo getinfo(Integer id) {
           // TODO Auto-generated method stub
          redisTemplate.opsForValue().set("id", itemServiceMapper.getinfo(id));//将实体写入缓存,在需要用到的地方用  
          redisTemplate.opsForValue().get("id"); //进行获取数据
            return  itemServiceMapper.getinfo(id);

    }
}
